/*
 * hkh-project
 * leafteamwork.blogspot.com
 * Tool: Netbeans 6.7.1 - SQL Server 2005
 */
package vn.com.hkh.service;

import java.util.Collection;
import vn.com.hkh.dto.UserDTO;
import vn.com.hkh.dao.UserDAO;
/**
 *
 * @author leaf
 */
public class UserService {

    UserDAO userDAO = new UserDAO();

    /**
     * Insert User
     * @param _dto
     * @return
     */
    public UserDTO create(UserDTO _dto) {
        return userDAO.create(_dto);
    }

    /**
     * Update User
     * @param _dto
     * @return
     */
    public UserDTO store(UserDTO _dto) {
        return userDAO.update(_dto);
    }

    /**
     * Update User password
     * @param _username
     * @param _newPassword
     * @return
     */
    public boolean store(String _username, String _newPassword) {        
        return userDAO.updatePassword(_username, _newPassword);
    }

    /**
     * Update User Status
     * @param _username
     * @param _status
     * @return boolean
     */
    public boolean store(String _username, Integer _status) {        
        return userDAO.updateStatus(_username, _status);
    }

    /**
     * List all Users
     * @return Collection<UserDTO>
     */
    public Collection<UserDTO> findUsers() {
        return userDAO.readByAll();
    }

    /**
     * List all Users by Status
     * @param _status
     * @return
     */
    public Collection<UserDTO> findByStatus(Integer _status) {
        return userDAO.readByStatus(_status);
    }

    /**
     * Find User by Primary key
     * @param _username
     * @return UserDTO
     */
    public UserDTO findByPrimaryKey(String _username) {
        return userDAO.readById(_username);
    }

    /**
     * Authenticate
     * @param _username
     * @param _password
     * @return UserDTO
     */
    public UserDTO authenticate(String _username, String _password) {
        return userDAO.authenticate(_username, _password);

    }

    /**
     * Delete User by Primary key
     * @param _username
     * @return boolean
     */
    public boolean remove(String _username) {
        return userDAO.deleteByID(_username);
    }
}
